{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [],
   "source": [
    "# Poiny点类\n",
    "class Point:\n",
    "    # 构造函数（构造方法）\n",
    "    def __init__(self, x, y):\n",
    "        # 属性初始化\n",
    "        self.x = x\n",
    "        self.y = y\n",
    "\n",
    "    # 实例方法也是类方法\n",
    "    def getDistance(self, other):\n",
    "        w = self.x - other.x\n",
    "        h = self.y - other.y\n",
    "        return (w**2 + h**2)**0.5"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "outputs": [],
   "source": [
    "import math\n",
    "\n",
    "class Point:\n",
    "    def __init__(self, x, y):\n",
    "        self.x = x\n",
    "        self.y = y\n",
    "\n",
    "    def __str__(self):\n",
    "        return f\"Point({self.x}, {self.y})\"\n",
    "\n",
    "    def __eq__(self, other):\n",
    "        return self.x == other.x and self.y == other.y\n",
    "\n",
    "    def getDistance(self, other):\n",
    "        w = self.x - other.x\n",
    "        h = self.y - other.y\n",
    "        return math.sqrt(w**2 + h**2)\n",
    "\n",
    "class Circle:\n",
    "    def __init__(self, o, r):\n",
    "        self.o = o\n",
    "        self.r = r\n",
    "\n",
    "    def __str__(self):\n",
    "        return f\"Circel({self.o}, {self.r})\"\n",
    "\n",
    "    def getArea(self):\n",
    "        return math.pi * self.r**2"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "p1 = Point(2, 3)\n",
    "p2 = Point(2, 3)\n",
    "print(p1 == p2)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Circel(Point(7, 11), 9)\n",
      "Circel(Hello, 11)\n",
      "380.132711084365\n"
     ]
    }
   ],
   "source": [
    "p = Point(7, 11)\n",
    "c = Circle(p, 9)\n",
    "print(c)\n",
    "c2 = Circle(\"Hello\", 11)\n",
    "print(c2)\n",
    "print(c2.getArea())"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Point(2, 3)\n",
      "Point(5, 7)\n",
      "5.0\n"
     ]
    }
   ],
   "source": [
    "p1 = Point(2, 3)\n",
    "p2 = Point(5, 7)\n",
    "print(p1)\n",
    "print(p2)\n",
    "print(p1.getDistance(p2))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 <class 'int'>\n",
      "10.23 <class 'float'>\n",
      "Hello, World <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "d = 10\n",
    "print(d, type(d))\n",
    "d = [1, 2, 3]\n",
    "print(d, type(d))\n",
    "d = \"Hello\"\n",
    "print(d, type(d))\n",
    "d = {\n",
    "    \"name\": \"Tom\",\n",
    "    \"age\": 11\n",
    "}\n",
    "print(d, type(d))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "age = 19\n",
    "age > 18\n",
    "age <= 19\n",
    "age != 12\n",
    "gender = \"male\"\n",
    "gender == \"female\"\n",
    "gender != \"male\"\n",
    "gender > \"z\"\n",
    "t = True\n",
    "t == False\n",
    "t != False"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "good\n"
     ]
    }
   ],
   "source": [
    "t = 23\n",
    "if t > 40:\n",
    "  print(\"hot\")\n",
    "elif t > 30:\n",
    "  print(\"warm\")\n",
    "elif t > 20:\n",
    "  print(\"good\")\n",
    "elif t > 10:\n",
    "  print(\"cold\")\n",
    "else:\n",
    "  print(\"veru cold\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5050\n",
      "finish\n"
     ]
    }
   ],
   "source": [
    "n = 1\n",
    "total = 0\n",
    "\n",
    "while n <= 100:\n",
    "    total += n\n",
    "    n += 1\n",
    "\n",
    "else:\n",
    "    print(total)\n",
    "\n",
    "print(\"finish\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "def add(*n):\n",
    "    total = 0\n",
    "\n",
    "    for x in n:\n",
    "        total += x\n",
    "\n",
    "    return total\n",
    "\n",
    "print(add(1, 2, 3))\n",
    "l = [1, 2, 3, 4]\n",
    "print(add(*l))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}